package socket.demo2;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;

public class Server {
    public static void main(String[] args) throws Exception {
        ServerSocket server = new ServerSocket(8080);
        Socket socket = server.accept();

        BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
        String line = reader.readLine();
        System.out.println("received data: " + line);

        PrintWriter writer = new PrintWriter(socket.getOutputStream());
        writer.println(line);
        writer.flush();

        writer.close();
        reader.close();

        socket.close();
        server.close();
    }
}
